// var parse = require('parse-link-header');
//
// var linkHeader =
//     '<https://api.github.com/posts?_page=0&_sort=date&_order=DESC&_embed=comments&_expand=user&_embed=likes>; rel="prev", ' +
//     '<https://api.github.com/posts?_page=0&_sort=date&_order=DESC&_embed=comments&_expand=user&_embed=likes>; rel="next"; _page=1 ; page=1, ' +
//     '<https://api.github.com/posts?_page=0&_sort=date&_order=DESC&_embed=comments&_expand=user&_embed=likes>; rel="last"'
//
// var parsed = parse(linkHeader);
// console.log(parsed);


// 上述 parse-link-header 实现过程不知道什么样的，这里直接对字符串进行操作
// var link = 'https://api.github.com/posts?_page=0&_sort=date&_order=DESC&_embed=comments&_expand=user&_embed=likes';
// let pageIndex = link.indexOf('_page=')+'_page='.length; // 35
// let pageNumber = +link.charAt(pageIndex); //
// pageNumber++;
// link = `${link.substring(0,pageIndex)}${pageNumber}${link.substring(pageIndex+1)}`;

// 函数 清楚单表所有数据
const fetch = require("isomorphic-fetch");

fetch('https://serve.social.letters.laimou5610.cn/api/posts',{
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
  },
  credentials: 'same-origin'
}).then(res => {
  return res.json()
      .then(posts => {
        posts.map(post => {
          fetch(`https://serve.social.letters.laimou5610.cn/api/posts/${post.id}`,{
            method: 'DELETE',
            headers: {
              'Content-Type': 'application/json',
            },
            credentials: 'same-origin'
          }).then(res => {
            return res.json()
                .then(dele => {
                  console.log(dele);
                })
          })
        })
      })
})
